package org.abc.utils
{
	import com.demonsters.debugger.MonsterDebugger;

	/**
	 * 调试工具
	 * @author aishi
	 *
	 */
	public class TraceUtil
	{
		private static var isDebugging:Boolean=true;

		/**
		 * 观察该数据
		 * @param obj
		 *
		 */
		public static function setMonster(obj:Object):void
		{
			MonsterDebugger.inspect(obj);
		}

		public static function traceString(obj:*):void
		{
			if (!isDebugging)
				return;
			if (obj is Array)
			{
				traceArray(obj);
				return;
			}
			trace(obj);
			return;
		}

		public static function demonsterTrace(tar:Object, obj:Object):void
		{
			if (!isDebugging)
				return;
			MonsterDebugger.trace(tar, obj);
			if (obj is String)
			{
				trace(tar, obj);
			}
			else
			{
				traceObject(obj);
			}
		}

		/**
		 * 打印数组
		 * @param arr
		 *
		 */
		public static function traceArray(arr:Array):void
		{
			if (!isDebugging)
				return;
			trace("----- //trace a array -----");
			for (var i:int=0; i < arr.length; i++)
			{
				trace("[" + i + "]" + arr[i]);
			}
			trace("----- //trace a array end -----");
		}

		/**
		 * 打印对象
		 * @param obj
		 *
		 */
		public static function traceObject(obj:Object):void
		{
			if (!isDebugging)
				return;
			trace("----- //trace a object -----");
			for (var key:* in obj)
			{
				trace(key + ":" + obj[key] + "\n");
			}
			trace("----- //trace a object end -----");
		}
	}
}
